package com.example.sport.ui.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.sport.R;


public class HomeFragment extends Fragment {

        //创建视图
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View inflate = inflater.inflate(R.layout.fragment_home, container, false);
            FragmentManager fragmentManager = getFragmentManager();

            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.frame_home
                    ,new CourseFragment());
            fragmentTransaction.commit();

            inflate.findViewById(R.id.bn_1_1).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击课程跳转
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frame_home
                            ,new CourseFragment());
                    fragmentTransaction.commit();
                }
            });
            inflate.findViewById(R.id.bn_1_2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击文章跳转
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frame_home
                            ,new ArtFragment());
                    fragmentTransaction.commit();
                }
            });
            return inflate;  //要加载的layout文件
        }

    }
